package LeetCode.leetcode234;

import java.util.ArrayList;

class Solution {
    public boolean isPalindrome(ListNode head) {
        ArrayList<ListNode> list = new ArrayList<>();
        ListNode p = head;
        while (p != null){
            list.add(p);
            p = p.next;
        }
        int lIndex = 0, rIndex = list.size()-1;
        while (lIndex <= rIndex){
            if (list.get(lIndex).val != list.get(rIndex).val) return false;
            lIndex++;
            rIndex--;
        }
        return true;
    }
}